package com.kefu.admin.common.zk.zkleader;

import com.kefu.admin.common.globals.ApplicationConstant;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicBoolean;

@Component
public class ApplicationContextHolder {
    public static volatile ApplicationContext context;

    @Deprecated
    public static volatile ApplicationConstant constant;
    private static AtomicBoolean startup = new AtomicBoolean(false);
    public static final ApplicationContextHolder INSTANCE = new ApplicationContextHolder();

    private ApplicationContextHolder() {
    }

    public static ApplicationContextHolder getInstance() {
        return INSTANCE;
    }

    public synchronized void init(ApplicationConstant applicationConstant) {
        constant = applicationConstant;
        //applicationConstant = (ApplicationConstant)context.getBean(ApplicationConstant.class);
    }

    public static boolean tryStartup() {
        return startup.compareAndSet(false, true);
    }

    public static boolean isStartup() {
        return startup.get();
    }
}